
# -*- coding: utf-8 -*-
from decimal import *
from math import *

def v2W(volt):
    if float(volt) < 0:
        return -1
    else:    
        watt = (float(volt) * 1100.0 / 1024.0) * 3000 / (0.9 * 100) / 1000  * 100
        watt = Decimal(str(watt)).quantize(Decimal('.0'), rounding=ROUND_HALF_UP)

        return watt

def v2L(volt):
    if float(volt) <= 0:
        return -1
    else:
        CON = 0.81
        OFFS = 1.22
        current = (((float(volt) * (1100.0 / 1024.0) )/ 1000.0) / 11.0) * 1000.0
        light = pow(10.0, (CON * log(current,10) + OFFS));
        light =  Decimal(str(light)).quantize(Decimal('.0'), rounding=ROUND_HALF_UP)

        return light


def v2T(volt):
    if float(volt) < 0:
        return -1
    else:
        temp = (float(volt) / 1024.0 * 1100.0 / 6.25) + (-424.0 / 6.25)
        temp = Decimal(str(temp)).quantize(Decimal('.0'), rounding=ROUND_HALF_UP)

    return temp

